package com.example.service.impl;

import com.example.entity.po.Dept;
import com.example.entity.po.Notice;
import com.example.mapper.DeptMapper;
import com.example.service.DeptService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hongyi
 * @date 2024/8/24 16:27
 */
@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public int insert(Dept dept) {
        return deptMapper.insert(dept);
    }

    @Override
    public int deleteById(Integer id) {
        return deptMapper.deleteById(id);
    }

    @Override
    public int updateById(Dept dept) {
        return deptMapper.updateById(dept);
    }

    @Override
    public Dept selectById(Integer id) {
        return deptMapper.selectById(id);
    }

    @Override
    public List<Dept> selectAll(Dept dept) {
        return deptMapper.selectAll(dept);
    }

    /**
     * 分页查询
     */
    public PageInfo<Dept> selectPage(Dept dept, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Dept> list = deptMapper.selectAll(dept);
        return PageInfo.of(list);
    }


    @Override
    public Dept selectByUsername(String name) {
        return deptMapper.selectByUsername(name);
    }

    @Override
    public void deleteBatch(List<Integer> ids) {
       for (int id: ids) {
           deptMapper.deleteById(id);
       }
    }
}
